package com.nomi.blog.exception;

import com.nomi.blog.utils.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result handlerException(Exception e) {
        e.printStackTrace();
        return Result.fail("系统异常，请稍后再尝试");
    }

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public Result handlerException(UnauthorizedException e) {
        return Result.fail(401,e.getMessage());
    }

    @ExceptionHandler(BussinessException.class)
    @ResponseBody
    public Result handlerException(BussinessException e) {
        return Result.fail(e.getCode(),e.getMessage());
    }
}
